home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
System Booster
/
System Booster.iso
/
Screenblankers
/
FT
/
win.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-26
|
11KB
|
485 lines
/*--------------------------------------------------------------------------*/
/* */
/* F l y i n g T o a s t e r s */
/* */
/* */
/* */
/*--------------------------------------------------------------------------*/
/* WIN.c */
/*--------------------------------------------------------------------------*/
#define WIN_C
#if ! defined(HEADER_PROCOMPILED)
# include "include.h"
#endif
#include "ft.h"
#include "win.h"
/*--------------------------------------------------------------------------
G L O B A L S
--------------------------------------------------------------------------*/
UCHAR *delay_txt[] = { "Turbo","Medium","Boring" };
struct Screen *scr;
struct Window *win,
*popup_win;
struct Gadget *glist;
struct VisualInfo *vi;
LOCAL struct Gadget *fm_gad;
/*--------------------------------------------------------------------------*/
/* show_delayrate */
/*--------------------------------------------------------------------------*/
LOCAL LONG __saveds __stdargs show_delayrate(struct Gadget *gad,WORD level)
{
delay_rate = (ULONG) level;
return((LONG) delay_txt[level - 1]);
} /* show_delayrate */
/*--------------------------------------------------------------------------*/
/* show_timeout */
/*--------------------------------------------------------------------------*/
LOCAL LONG __saveds __stdargs show_timeout(struct Gadget *gad,WORD level)
{
static UCHAR buf[15];
sprintf(buf,"%2u:%02u",level / 60, level % 60);
timeout_ticks = (level * TICKSPERMIN) / 60;
return((LONG) buf);
} /* show_timeout */
/*--------------------------------------------------------------------------*/
/* show_nr_objects */
/*--------------------------------------------------------------------------*/
LOCAL LONG __saveds __stdargs show_nr_objects(struct Gadget *gad,WORD level)
{
static UCHAR buf[15];
if (level == 0)
strcpy(buf,"no objects");
else
sprintf(buf,"%2u Objects",level);
nr_objects = level;
return((LONG) buf);
} /* show_nr_objects */
/*--------------------------------------------------------------------------*/
/* open_popupwin */
/*--------------------------------------------------------------------------*/
BOOLEAN open_popupwin(void)
{
UINT i;
struct Gadget *gad;
if ((prefs_menu = CreateMenus(prefs_nmenu,
GTNM_Border,(Tag) TRUE,
GTMN_TextAttr,(Tag) &ta_courier,
TAG_END)) == NULL) {
return(FALSE);
}
if ((popup_win = OpenWindowTagList(NULL,popup_win_tag)) == NULL)
return(FALSE);
if ((vi = GetVisualInfo(popup_win->WScreen,TAG_END)) == NULL)
return(FALSE);
if (LayoutMenusA(prefs_menu,vi,NULL) == 0)
return(FALSE);
for (i = 0; i < GADGETMAX; i++)
ng[i].ng_VisualInfo = vi;
ng[GAD_OBJECTS].ng_TopEdge = popup_win->BorderTop + GAP +
ng[GAD_OBJECTS].ng_Height;
ng[GAD_OBJECTS].ng_LeftEdge = popup_win->BorderLeft + 2 * GAP;
ng[GAD_TIMEOUT].ng_TopEdge = ng[GAD_OBJECTS].ng_TopEdge +
2 * ng[GAD_OBJECTS].ng_Height + 2 * GAP;
ng[GAD_TIMEOUT].ng_LeftEdge = ng[GAD_OBJECTS].ng_LeftEdge;
ng[GAD_DELAYRATE].ng_TopEdge = ng[GAD_TIMEOUT].ng_TopEdge +
2 * ng[GAD_TIMEOUT].ng_Height + 2 * GAP;
ng[GAD_DELAYRATE].ng_LeftEdge = ng[GAD_TIMEOUT].ng_LeftEdge;
ng[GAD_SLEEP].ng_TopEdge = ng[GAD_DELAYRATE].ng_TopEdge +
2 * ng[GAD_DELAYRATE].ng_Height + 2 * GAP;
ng[GAD_SLEEP].ng_LeftEdge = ng[GAD_DELAYRATE].ng_LeftEdge;
ng[GAD_NEVER].ng_TopEdge = ng[GAD_SLEEP].ng_TopEdge;
ng[GAD_NEVER].ng_LeftEdge = ng[GAD_SLEEP].ng_LeftEdge +
ng[GAD_SLEEP].ng_Width + GAP;
glist = NULL;
if ((gad = CreateContext(&glist)) == NULL)
return(FALSE);
gad = CreateGadget(SLIDER_KIND,gad,&ng[GAD_OBJECTS],
GTSL_Max, OBJECTMAX,
GTSL_Min, 0,
GTSL_DispFunc, show_nr_objects,
GTSL_Level, nr_objects,
GTSL_LevelFormat, "%s",
GTSL_LevelPlace, PLACETEXT_RIGHT,
GTSL_MaxLevelLen, 15,
PGA_Freedom, LORIENT_HORIZ,
TAG_END);
if (gad == NULL)
return(FALSE);
gad = CreateGadget(SLIDER_KIND,gad,&ng[GAD_TIMEOUT],
GTSL_Max, 30 * 60,
GTSL_Min, 5,
GTSL_DispFunc, show_timeout,
GTSL_Level, (timeout_ticks * 60) / TICKSPERMIN,
GTSL_LevelFormat, "%s",
GTSL_LevelPlace, PLACETEXT_RIGHT,
GTSL_MaxLevelLen, 15,
PGA_Freedom, LORIENT_HORIZ,
TAG_END);
if (gad == NULL)
return(FALSE);
gad = CreateGadget(SLIDER_KIND,gad,&ng[GAD_DELAYRATE],
GTSL_Max, 3,
GTSL_Min, 1,
GTSL_DispFunc, show_delayrate,
GTSL_Level, delay_rate,
GTSL_LevelFormat, "%-8s",
GTSL_LevelPlace, PLACETEXT_RIGHT,
GTSL_MaxLevelLen, 8,
PGA_Freedom, LORIENT_HORIZ,
TAG_END);
if (gad == NULL)
return(FALSE);
gad = CreateGadget(BUTTON_KIND,gad,&ng[GAD_HIDE],TAG_END);
gad->Flags |= GFLG_RELBOTTOM;
gad->LeftEdge += popup_win->BorderLeft;
if (gad == NULL)
return(FALSE);
gad = CreateGadget(BUTTON_KIND,gad,&ng[GAD_QUIT],TAG_END);
gad->Flags |= GFLG_RELBOTTOM;
gad->LeftEdge += popup_win->BorderLeft;
if (gad == NULL)
return(FALSE);
gad = CreateGadget(BUTTON_KIND,gad,&ng[GAD_BLANK],TAG_END);
gad->Flags |= GFLG_RELBOTTOM;
gad->LeftEdge += popup_win->BorderLeft;
if (gad == NULL)
return(FALSE);
ng[GAD_FLIGHT_MODE].ng_LeftEdge = BEVEL_X;
ng[GAD_FLIGHT_MODE].ng_TopEdge = BEVEL_Y + BEVEL_DY + GAP;
gad = fm_gad = CreateGadget(MX_KIND,gad,&ng[GAD_FLIGHT_MODE],
GTMX_Labels, flight_mode_txt,
GTMX_Spacing, 2,
TAG_END);
if (gad == NULL)
return(FALSE);
gad = CreateGadget(CYCLE_KIND,gad,&ng[GAD_SLEEP],
GTCY_Labels, corner_txt,
GTCY_Active, csleep,
TAG_END);
if (gad == NULL)
return(FALSE);
gad = CreateGadget(CYCLE_KIND,gad,&ng[GAD_NEVER],
GTCY_Labels, corner_txt,
GTCY_Active, cnever,
TAG_END);
if (gad == NULL)
return(FALSE);
AddGList(popup_win,glist,0,-1,NULL);
DrawBevelBox(popup_win->RPort,BEVEL_X,BEVEL_Y,BEVEL_DX,BEVEL_DY,
GT_VisualInfo,vi, TAG_END);
RefreshGadgets(glist,popup_win,NULL);
GT_RefreshWindow(popup_win,NULL);
SetMenuStrip(popup_win,prefs_menu);
return(TRUE);
} /* open_popupwin */
/*--------------------------------------------------------------------------*/
/* close_popupwin */
/*--------------------------------------------------------------------------*/
void close_popupwin(void)
{
if (popup_win != NULL) {
CloseWindow(popup_win);
popup_win = NULL;
}
if (prefs_menu != NULL) {
FreeMenus(prefs_menu);
prefs_menu = NULL;
}
if (glist == NULL) {
FreeGadgets(glist);
glist = NULL;
}
if (vi != NULL)
FreeVisualInfo(vi);
} /* close_popupwin */
/*--------------------------------------------------------------------------*/
/* open_display */
/*--------------------------------------------------------------------------*/
BOOLEAN open_display(void)
{
if ((scr = OpenScreenTagList(NULL,scr_tags)) == NULL)
return(FALSE);
win_tags[7].ti_Data = (LONG) scr;
win_tags[2].ti_Data = (LONG) scr->Width;
win_tags[3].ti_Data = (LONG) scr->Height;
if ((win = OpenWindowTagList(NULL,win_tags)) == NULL)
return(FALSE);
ScreenToFront(scr);
SetAPen(win->RPort,0);
WaitTOF();
SetPointer(win,pointer_data,POINTER_HEIGHT,POINTER_WIDTH,1,1);
return(TRUE);
} /* open_display */
/*--------------------------------------------------------------------------*/
/* close_display */
/*--------------------------------------------------------------------------*/
void close_display(void)
{
if (win != NULL) {
CloseWindow(win);
win = NULL;
}
if (scr != NULL) {
CloseScreen(scr);
scr = NULL;
}
} /* close_display */
/*--------------------------------------------------------------------------*/
/* open_prefs */
/*--------------------------------------------------------------------------*/
struct ft_msg * open_prefs(void)
{
BOOLEAN display_about;
INT freq,
code,
txt_index,
class;
struct IntuiMessage *imsg;
struct Gadget *gad;
struct MenuItem *mi;
struct ft_msg *ft_msg;
struct object obj;
struct sequence *flight_seq;
if (! open_popupwin()) {
close_popupwin();
return(NULL);
}
memset(&obj,'\0',sizeof(obj));
obj.seq = &default_seq;
freq = 0;
display_about = FALSE;
flight_seq = NULL;
FOREVER {
Delay(delay_rate);
if ((imsg = GT_GetIMsg(popup_win->UserPort)) != NULL) {
gad = (struct Gadget *) imsg->IAddress;
class = imsg->Class;
code = imsg->Code;
GT_ReplyIMsg(imsg);
switch (class) {
case IDCMP_CLOSEWINDOW:
close_popupwin();
return(NULL);
case IDCMP_GADGETUP:
switch (gad->GadgetID) {
case GAD_SLEEP:
csleep = code;
if (csleep != CO_DISABLED && cnever == csleep) {
csleep = (code + 1) % (CO_DISABLED + 1);
GT_SetGadgetAttrs(gad,popup_win,NULL,
GTCY_Active, csleep,
TAG_END);
}
break;
case GAD_NEVER:
cnever = code;
if (cnever != CO_DISABLED && cnever == csleep) {
cnever = (code + 1) % (CO_DISABLED + 1);
GT_SetGadgetAttrs(gad,popup_win,NULL,
GTCY_Active, cnever,
TAG_END);
}
break;
case GAD_HIDE:
close_popupwin();
return(NULL);
case GAD_QUIT:
Signal(main_task,SIGBREAKF_CTRL_C);
close_popupwin();
return(NULL);
case GAD_BLANK:
close_popupwin(); // simulate msg
return(init_ftmsg(BA_BLANK));
} // switch
break;
case IDCMP_GADGETDOWN:
switch (gad->GadgetID) {
case GAD_FLIGHT_MODE:
flight_seq = seq_list[code];
break;
} // switch
break;
case IDCMP_MENUPICK:
while ((mi = ItemAddress(prefs_menu,code)) != NULL) {
switch ((UINT) GTMENUITEM_USERDATA(mi)) {
case MN_BLANK:
close_popupwin(); // simulate msg
return(init_ftmsg(BA_BLANK));
case MN_HIDE:
close_popupwin();
return(NULL);
case MN_QUIT:
Signal(main_task,SIGBREAKF_CTRL_C);
close_popupwin();
return(NULL);
case MN_ABOUT:
freq = txt_index = 0;
display_about = TRUE;
break;
case MN_FREE_FLIGHT:
case MN_DEF_FLIGHT:
case MN_LOOP:
case MN_FACE2FACE:
code = (UINT) GTMENUITEM_USERDATA(mi) - MN_FREE_FLIGHT;
GT_SetGadgetAttrs(fm_gad,popup_win,NULL,
GTMX_Active,code,
TAG_END);
flight_seq = seq_list[code];
break;
} // switch
code = mi->NextSelect;
} // while
break;
} // switch
}
if ((ft_msg = (struct ft_msg *) GetMsg(ft_port)) != NULL) {
if (ft_msg->ftm_action != BA_POPUP_PREFS) {
close_popupwin();
return(ft_msg);
}
free(ft_msg);
}
if (! display_about) {
freq++;
if (freq == 2) {
freq = 0;
goto_next_img(&obj,flight_seq);
DrawImage(popup_win->RPort,obj.seq->img[obj.phase],FT_X,FT_Y);
}
}
else {
freq++;
WaitTOF();
ScrollRaster(popup_win->RPort,0,2,BEVEL_X + GAP, BEVEL_Y + GAP,
BEVEL_X + BEVEL_DX - GAP,
BEVEL_Y + BEVEL_DY - GAP);
if (freq == 6) {
freq = 0;
if (about_txt[txt_index] != NULL) {
itxt.IText = about_txt[txt_index];
PrintIText(popup_win->RPort,&itxt,BEVEL_X + GAP,
BEVEL_Y + BEVEL_DY - GAP - 11);
txt_index++;
if (about_txt[txt_index] == NULL)
freq = - BEVEL_DY;
}
else
display_about = FALSE;
}
}
} // forever
} /* open_prefs */